/*
 * ContentStatusQueryElement.java
 *
 * Created on September 8, 2007, 9:24 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.adl.registry.website.lucene;

import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Jacob
 */
public class ContentStatusQueryElement implements QueryElement
{
    private static final String LUCENE_FIELD = "statusValue";
    
    private ArrayList<String> mElementParts;
    
    /** Creates a new instance of ContentStatusQueryElement */
    public ContentStatusQueryElement()
    {
        this.mElementParts = new ArrayList<String>();
    }
    
    public void addStatus(String value)
    {
        if ((value == null) || (value.length() == 0))
        {
            //TODO: throw exception
        }
        
        this.mElementParts.add(value);
    }
    
    public String toString()
    {
        StringBuilder builder = new StringBuilder();
        
        int counter = 0;
        
        Iterator<String> iterator = this.mElementParts.iterator();
        
        while(iterator.hasNext())
        {
            String value = iterator.next();
            
            if (counter == 0)
            {
                String formatted = this.LUCENE_FIELD + ":\"" + value + "\"";
                
                builder.append(formatted);
            }
            else
            {
                //TODO: get default operator
                
                String formatted = " AND " + this.LUCENE_FIELD + ":\"" + value + "\"";
                
                builder.append(formatted);
            }
            
            counter++;
        }
        
        return builder.toString();
    }
}
